home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / prlgbnc1.lha / Bench / prover.pl < prev    next >
Text File  |  1990-06-01  |  2KB  |  97 lines

  1. % generated: 30 October 1989
  2. % option(s): 
  3. %
  4. %   prover
  5. %
  6. %   Richard A. O'Keefe
  7. %
  8. %   Prolog theorem prover
  9. %
  10. %   from "Prolog Compared with Lisp?," SIGPLAN Notices, v. 18 #5, May 1983
  11.  
  12. % op/3 directives
  13.  
  14. :- op(950, xfy, #).    % disjunction
  15. :- op(850, xfy, &).    % conjunction
  16. :- op(500, fx, +).    % assertion
  17. :- op(500, fx, -).    % denial
  18.  
  19. prover :- problem(_, P, C),
  20.       implies(P, C),
  21.       fail.
  22. prover.
  23.  
  24. % problem set
  25.  
  26. problem( 1, -a, +a).
  27.  
  28. problem( 2, +a, -a & -a).
  29.  
  30. problem( 3, -a, +to_be # -to_be).
  31.  
  32. problem( 4, -a & -a, -a).
  33.  
  34. problem( 5, -a, +b # -a).
  35.  
  36. problem( 6, -a & -b, -b & -a).
  37.  
  38. problem( 7, -a, -b # (+b & -a)).
  39.  
  40. problem( 8, -a # (-b # +c), -b # (-a # +c)).
  41.  
  42. problem( 9, -a # +b, (+b & -c) # (-a # +c)).
  43.  
  44. problem( 10, (-a # +c) & (-b # +c), (-a & -b) # +c).
  45.  
  46. % Prolog theorem prover
  47.  
  48. implies(Premise, Conclusion) :-
  49.     opposite(Conclusion, Denial),
  50.     add_conjunction(Premise, Denial, fs([],[],[],[])).
  51.  
  52. opposite(F0 & G0, F1 # G1) :- !,
  53.     opposite(F0, F1),
  54.     opposite(G0, G1).
  55. opposite(F1 # G1, F0 & G0) :- !,
  56.     opposite(F1, F0),
  57.     opposite(G1, G0).
  58. opposite(+Atom, -Atom) :- !.
  59. opposite(-Atom, +Atom).
  60.  
  61. add_conjunction(F, G, Set) :-
  62.     expand(F, Set, Mid),
  63.     expand(G, Mid, New),
  64.     refute(New).
  65.  
  66. expand(_, refuted, refuted) :- !.
  67. expand(F & G, fs(D,_,_,_), refuted) :-
  68.     includes(D, F & G), !.
  69. expand(F & G, fs(D,C,P,N), fs(D,C,P,N)) :-
  70.     includes(C, F & G), !.
  71. expand(F & G, fs(D,C,P,N), New) :- !,
  72.     expand(F, fs(D,[F & G|C],P,N), Mid),
  73.     expand(G, Mid, New).
  74. expand(F # G, fs(D,C,P,N), Set) :- !,
  75.     opposite(F # G, Conj),
  76.     extend(Conj, D, C, D1, fs(D1,C,P,N), Set).
  77. expand(+Atom, fs(D,C,P,N), Set) :- !,
  78.     extend(Atom, P, N, P1, fs(D,C,P1,N), Set).
  79. expand(-Atom, fs(D,C,P,N), Set) :-
  80.     extend(Atom, N, P, N1, fs(D,C,P,N1), Set).
  81.  
  82. includes([Head|_], Head) :- !.
  83. includes([_|Tail], This) :- includes(Tail, This).
  84.  
  85. extend(Exp, _, Neg, _, _, refuted) :- includes(Neg, Exp), !.
  86. extend(Exp, Pos, _, Pos, Set, Set) :- includes(Pos, Exp), !.
  87. extend(Exp, Pos, _, [Exp|Pos], Set, Set).
  88.  
  89. refute(refuted) :- !.
  90. refute(fs([F1 & G1|D], C, P, N)) :-
  91.     opposite(F1, F0),
  92.     opposite(G1, G0),
  93.     Set = fs(D, C, P, N),
  94.     add_conjunction(F0, G1, Set),
  95.     add_conjunction(F0, G0, Set),
  96.     add_conjunction(F1, G0, Set).
  97.